package com.sceneworker.extensions.dome;

import com.acarter.propertytable.Property;
import com.acarter.propertytable.PropertySection;
import com.acarter.propertytable.propertyobject.BooleanPropertyObject;
import com.acarter.propertytable.propertyobject.FloatPropertyObject;
import com.acarter.propertytable.propertyobject.IntegerPropertyObject;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Dome;
import com.jme2utils.staticutils.GenericJMEUtils;
import com.sceneworker.extensions.trimesh.TriMeshPropertyPage;

public class DomePropertyPage extends TriMeshPropertyPage {

	public DomePropertyPage() {
		super();
		
		PropertySection		lcl_section = new PropertySection("Dome");
		lcl_section.addProperty(new Property("Planes", new IntegerPropertyObject()));
		lcl_section.addProperty(new Property("Radial Samples", new IntegerPropertyObject()));
		lcl_section.addProperty(new Property("Radius", new FloatPropertyObject()));
		lcl_section.addProperty(new Property("Outside View", new BooleanPropertyObject()));
		
		model.addPropertySection(0, lcl_section);
	}
	
	@Override
	protected void updateListeners(final Spatial spatial) {

		super.updateListeners(spatial);
		
		if(!(spatial instanceof Dome)) { return; }
		
		final	Dome	lcl_dome = (Dome)spatial;

		PropertySection		lcl_section = model.getPropertySection("Dome");
		
		IntegerPropertyObject		lcl_planes = (IntegerPropertyObject)lcl_section.getProperty("Planes").getPropertyObject();
		lcl_planes.SetListener(new IntegerPropertyObject.I_IntegerPropertyObjectListener() {

			public int readValue() {
				return lcl_dome.getPlanes();
			}

			public void saveValue(int value) {
				GenericJMEUtils.updateGeometry(lcl_dome, lcl_dome.getCenter(), value, lcl_dome.getRadialSamples(),	lcl_dome.getRadius(), lcl_dome.isOutsideView());
			}

		});
		
		IntegerPropertyObject		lcl_radialSamples = (IntegerPropertyObject)lcl_section.getProperty("Radial Samples").getPropertyObject();
		lcl_radialSamples.SetListener(new IntegerPropertyObject.I_IntegerPropertyObjectListener() {

			public int readValue() {
				return lcl_dome.getRadialSamples();
			}

			public void saveValue(int value) {
				GenericJMEUtils.updateGeometry(lcl_dome, lcl_dome.getCenter(), lcl_dome.getPlanes(), value, lcl_dome.getRadius(), lcl_dome.isOutsideView());	
			}

		});

		FloatPropertyObject		lcl_radius = (FloatPropertyObject)lcl_section.getProperty("Radius").getPropertyObject();
		lcl_radius.SetListener(new FloatPropertyObject.I_FloatPropertyObjectListener() {

			public float readValue() {
				return lcl_dome.getRadius();
			}

			public void saveValue(float value) {
				GenericJMEUtils.updateGeometry(lcl_dome, lcl_dome.getCenter(), lcl_dome.getPlanes(), lcl_dome.getRadialSamples(), value, lcl_dome.isOutsideView()); 
			}

		});
		
		BooleanPropertyObject		lcl_outside = (BooleanPropertyObject)lcl_section.getProperty("Outside View").getPropertyObject();
		lcl_outside.SetListener(new BooleanPropertyObject.I_BooleanPropertyObjectListener() {

			public boolean readValue() {
				return lcl_dome.isOutsideView();
			}

			public void saveValue(boolean value) {
				GenericJMEUtils.updateGeometry(lcl_dome, lcl_dome.getCenter(), lcl_dome.getPlanes(), lcl_dome.getRadialSamples(), lcl_dome.getRadius(), value);
			}

		});
		
		
	}

}
